<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page session="false"%>
<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>添加/修改媒体</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <link href="<c:url value="/resources/css/normalize.css" />" rel="stylesheet" type="text/css" />
		<link href="<c:url value="/resources/css/lib.css" />" rel="stylesheet" type="text/css" />
        <link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css" />

        <script src="<c:url value="/resources/jquery/jquery.js" />"></script>
        <script src="<c:url value="/resources/jqueryui/1.8/jquery-ui-1.8.16.custom.min.js" />"></script>
        
        <script src="<c:url value="/resources/ckeditor/ckeditor.js" />"></script>
        
        <script src="<c:url value="/resources/scripts/regionUtil.js" />"></script>
        <script src="<c:url value="/resources/scripts/categoryUtil.js" />"></script>
        <style>
        	
        </style>
    </head>
    <body>
        <form:form action='' method="post" modelAttribute="product" enctype="multipart/form-data">
        <c:if test="${not empty message}">
            <div id="message" class="success">
                ${message}
            </div>
        </c:if>
        <table class="regTable">
            <caption style="text-align:left" class="lh30 b f14">
                <form:hidden path="id" />
                <form:hidden path="regionId" />
                <form:hidden path="categoryId" id="categoryId" />
                <span>添加/修改媒体</span>
            </caption>
            <tbody>
                <tr>
                    <td colspan="2" class="b">基本信息</td>
                </tr>
                <c:if test="${isAdmin==true}">
                <tr>
                	<td align="right">会员:</td>
                	<td>
                		<form:select path="memberId">
                			<form:options items="${allMembers}" itemValue="id" itemLabel="name" />
                		</form:select>
                	</td>
                </tr>
                </c:if>
                <tr>
                    <td width="20%" align="right">分类:</td>
                    <td width="80%">
                    	<span id="categorySelContainer"></span>
                    	<form:errors path="categoryId"  />
                    </td>
                </tr>
                <tr>
                    <td align="right">名称:</td>
                    <td>
                    	<form:input path="name" cssClass="input-style1"/>
                    	<span class="red"> * <form:errors path="name"  /></span>
                    </td>
                    
                </tr>
                <tr>
                    <td align="right">区域:</td>
                    <td>
                    	<span id="regionSelectorContainer"></span>
                    	<span class="red"> * <form:errors path="regionId"  /></span>	
                    </td>
                </tr>
                <tr>
                    <td align="right">计价单位:</td>
                    <td>
                    	<form:input path="unit" cssClass="input-style1"/>
                    	<span class="red"> * <form:errors path="unit"  /></span>	
                    </td>
                    
                </tr>
                <tr>
                    <td align="right">价格:</td>
                    <td>
                    	<form:input path="price" cssClass="input-style1"/>
                    	<span class="red"> * <form:errors path="price"  /></span>	
                    </td>
                </tr>
                <tr>
                    <td align="right">小图:</td>
                    <td>
                    	<c:if test="${product.iconImage ne null}">
                    	<img width="80" height="80" src="<c:url value="/upload/images/" />${product.iconImage}" /><br />
                    	<input type="hidden" name="iconImage" value="${product.iconImage}" />
                    	</c:if>
                    	<form:input type="file" path="iconImageFile" />
                    	<span class="red"><form:errors path="iconImageFile" /></span>
                    </td>
                </tr>
                <tr>
                    <td align="right">大图:</td>
                    <td>
                    	<c:if test="${product.bigImage ne null}">
                    	<img width="260" height="260" src="<c:url value="/upload/images/" />${product.bigImage}" /><br />
                    	<input type="hidden" name="bigImage" value="${product.bigImage}" />
                    	</c:if>
                    	<form:input type="file" path="bigImageFile" />
                    	<span class="red"><form:errors path="bigImageFile" /></span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="b">描述信息</td>
                </tr>
                <c:forEach var="pd" items="${product.productDetails}" varStatus="status">
                <tr>
                    <td align="right">
                        ${pd.categoryAttr.attrName}: 
                        <c:if test="${pd.id ne null}">
                        	<input type="hidden" name="productDetails[${status.index}].id" value="${pd.id}" />
                        </c:if>
                        <input type="hidden" name="productDetails[${status.index}].categoryAttr.id" value="${pd.categoryAttr.id}" />
                        <input type="hidden" name="productDetails[${status.index}].categoryAttr.attrName" value="${pd.categoryAttr.attrName}" />
                    </td>
                    <td><input name="productDetails[${status.index}].attrValue" value="${pd.attrValue}" class="input-style1"/></td>
                </tr>
                </c:forEach>
                <tr>
                   	<td align="right">验证码:</td>
                   	<td>
                   		<form:input path="validCode" /><span class="red mr5"> *</span> 
                   		<img src="<c:url value="/validCode" />" id="validCodeImg" class="vm"/>
                   		<span class="red"> <form:errors path="validCode"  /></span>
                   	</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="提交" />
                    </td>
                </tr>
                <tr>
                	<td colspan="2" class="b">详细描述:</td>
                </tr>
                <tr>
                    <td colspan="2">
                    	<form:errors path="description" cssClass="red" />
                    	<form:textarea path="description" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="提交" />
                        <!--input type="reset" value="重置表单" /-->
                    </td>
                </tr>
            </tbody>
            
        </table>
        <br />
        </form:form>
    </body>
</html>

<script>

var productUpdateUrl = '<c:url value="/product/update" />';
$(document).ready(function(){
	
	$('#product').attr('action', productUpdateUrl);
    RegionUtil.restoreSel();
    //CategoryUtil.restoreSel();
    $('#categorySelContainer').html(CategoryUtil.getPath());
    /**
    $('input:text').each(function(){
    	if($(this).val()=='') $(this).val(5);
    });
    **/
    CKEDITOR.replace('description', {
    	language: 'zh-cn',
		skin: 'office2003'
	});
	
	$('#validCodeImg').click(function(){
    	var validCodeUrl = '<c:url value="/validCode" />?';
    	$(this).attr('src', validCodeUrl + new Date);
    });
        
});
</script>
